/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import org.hibernate.mapping.Set;
/**
 *
 * @author Elias Mendoza
 */
@Entity
@Table(name="historial")
public class Historial implements Serializable{
  @Id
  @GeneratedValue(strategy= GenerationType.IDENTITY)
  private int id;
  @Column(name="dia_noche",nullable=false)
  private int diaNoche;
  @Column(nullable=false)
  @Temporal(javax.persistence.TemporalType.DATE)
  private Date fecha;
  //***********Estableciendo la relacion uno a muchos (un historial muchos sensor_registro)
  @OneToMany(cascade= CascadeType.ALL,fetch= FetchType.EAGER,mappedBy="historial")
  private List<Lectura> lectura= new ArrayList<Lectura>();

  //**************************************************************************************
  //********Creando relacion 1:M (relacion original N:M) de historial y Sustrato
//  @OneToMany(cascade = CascadeType.ALL, mappedBy = "primaryKey.historialFK")
//  private List<SensorRegistroSustrato> historialSustrato = new ArrayList<SensorRegistroSustrato>();
  //**************************************************************************************

  public Historial() {
  }

  public Historial(int id) {
    this.id = id;
  }

  public List<Lectura> getLectura() {
    return lectura;
  }

  public void setLectura(List<Lectura> lectura) {
    this.lectura = lectura;
  }

  public int getDiaNoche() {
    return diaNoche;
  }

  public void setDiaNoche(int diaNoche) {
    this.diaNoche = diaNoche;
  }
  
  public Date getFecha() {
    return fecha;
  }

  public void setFecha(Date fecha) {
    this.fecha = fecha;
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  @Override
  public String toString() {
    return "Historial{" + "id=" + id + '}';
  }
  //espacio para metodos equals y hashCode

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final Historial other = (Historial) obj;
    if (this.id != other.id) {
      return false;
    }
    if (this.diaNoche != other.diaNoche) {
      return false;
    }
    if (this.fecha != other.fecha && (this.fecha == null || !this.fecha.equals(other.fecha))) {
      return false;
    }
    if (this.lectura != other.lectura && (this.lectura == null || !this.lectura.equals(other.lectura))) {
      return false;
    }
    return true;
  }

  @Override
  public int hashCode() {
    int hash = 5;
    hash = 97 * hash + this.id;
    hash = 97 * hash + this.diaNoche;
    hash = 97 * hash + (this.fecha != null ? this.fecha.hashCode() : 0);
    hash = 97 * hash + (this.lectura != null ? this.lectura.hashCode() : 0);
    return hash;
  }


  
  
}
